home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Graphics / Plotting / aa_Intel_Only / Gnuplot / GnuplotSource / ThreeDPane.m < prev    next >
Encoding:
Text File  |  1995-06-12  |  7.8 KB  |  386 lines

  1. /*
  2.  *  Copyright (C) 1993  Robert Davis
  3.  *
  4.  *  This program is free software; you can redistribute it and/or
  5.  *  modify it under the terms of Version 2, or any later version, of 
  6.  *  the GNU General Public License as published by the Free Software 
  7.  *  Foundation.
  8.  */
  9.  
  10. static char RCSId[]="$Id: ThreeDPane.m,v 1.8 1993/05/18 03:55:44 davis Exp $";
  11.  
  12.  
  13. #import <appkit/Application.h>
  14. #import <appkit/Box.h>
  15. #import <appkit/Matrix.h>
  16. #import <appkit/Slider.h>
  17. #import <appkit/TextField.h>
  18. #import <appkit/TextFieldCell.h>
  19. #import <appkit/View.h>
  20.  
  21. #import "ContourOptionsPanel.h"
  22. #import "GnuplotPlot.h"
  23. #import "Status.h"
  24. #import "StatusContour.h"
  25. #import "ThreeDPane.h"
  26.  
  27.  
  28. #define    SURF_WIREFRAME    0
  29. #define    SURF_OPAQUE    1
  30. #define    SURF_INVISIBLE    2
  31.  
  32.  
  33. @interface ThreeDPane (Private)
  34.  
  35. - _updateRotationIsThreeD:(BOOL)isThreeD;
  36. - _updateContourIsThreeD:(BOOL)isThreeD;
  37. - _updateSurfaceTypeIsThreeD:(BOOL)isThreeD;
  38. - _updateIsoSamplesIsThreeD:(BOOL)isThreeD;
  39.  
  40. @end
  41.  
  42.  
  43.  
  44.  
  45. @implementation ThreeDPane
  46.  
  47.  
  48. - init
  49. {
  50.     [super init];
  51.  
  52.     [NXApp loadNibSection: "ThreeDPane.nib"
  53.             owner: self
  54.         withNames: NO
  55.          fromZone: [self zone]];
  56.  
  57.     icon = "InspectorThreeD.tiff";
  58.  
  59.     return self;
  60. }
  61.  
  62.  
  63. - free
  64. {
  65.     if (contourOptionsPanel)
  66.     [contourOptionsPanel free];
  67.  
  68.     return [super free];
  69. }
  70.  
  71.  
  72. /*  
  73.  *  Overridden from Pane.
  74.  */
  75. - selectControl:sender
  76. {
  77.     [isoSamplesMatrix selectText:self];
  78.     return self;
  79. }
  80.  
  81.  
  82. - (BOOL)updateStatus:aStatus doc:aDoc
  83. {
  84.     id oldStatus = status;
  85.     id oldDoc = doc;
  86.  
  87.     /*  
  88.      *  We only bother updating if status has changed since we last 
  89.      *  updated, or if we just became the current pane (didSwap) -- 
  90.      *  assuming that status and aDoc are non-nil, of course.
  91.      */
  92.  
  93.     if ([super updateStatus:aStatus doc:aDoc]
  94.     && ((status != oldStatus) || didSwap)) {
  95.  
  96.     BOOL isThreeD, isPolar;
  97.     Window *viewWindow;
  98.  
  99.     [(viewWindow = [view window]) disableDisplay];
  100.  
  101.         [threeDButton setState:(isThreeD = [status isThreeD])];
  102.         [threeDButton setEnabled:!(isPolar = [status isPolar])];
  103.  
  104.         [self _updateRotationIsThreeD:isThreeD];
  105.     [self _updateContourIsThreeD:isThreeD];
  106.     [self _updateSurfaceTypeIsThreeD:isThreeD];
  107.     [self _updateIsoSamplesIsThreeD:isThreeD];
  108.  
  109.     [viewWindow reenableDisplay];
  110.  
  111.     [self perform:@selector(selectControl:)
  112.          with:self
  113.        afterDelay:1
  114.        cancelPrevious:YES];
  115.  
  116.     didSwap = NO;
  117.     return YES;
  118.     }
  119.  
  120.     return NO;
  121. }
  122.  
  123.  
  124. - (BOOL)forceUpdateStatus:aStatus doc:aDoc
  125. {
  126.     BOOL    needsRedisplay;
  127.  
  128.     /*  Update ourselves first, then the options panel  */
  129.     
  130.     needsRedisplay = [super forceUpdateStatus:aStatus doc:aDoc];
  131.  
  132.     if ([[contourOptionsPanel panel] isVisible])
  133.     [contourOptionsPanel forceUpdate];
  134.  
  135.     return needsRedisplay;
  136. }
  137.  
  138.  
  139.  
  140. - didSwapIn:sender
  141. {
  142.     [super didSwapIn:self];
  143.     didSwap = YES;
  144.     return self;
  145. }
  146.  
  147.  
  148. - doSetThreeD:sender
  149. {
  150.     BOOL isThreeD;
  151.  
  152.     [status setThreeD:isThreeD = [sender state]];
  153.  
  154.     /*  
  155.      *  Making changes that might affect other controls in the same 
  156.      *  pane or one of our options panels should update the pane using 
  157.      *  the current status and doc.
  158.      */
  159.     
  160.     if ([self forceUpdateStatus:status doc:doc])
  161.     [view display];
  162.  
  163.     return self;
  164. }
  165.  
  166.  
  167. - doSetSurfaceType:sender
  168. {
  169.     BOOL oldReport = [status report];
  170.  
  171.     [status setReport:NO];
  172.  
  173.     switch ([surfaceTypeMatrix selectedTag]) {
  174.     case SURF_WIREFRAME:
  175.     [status setSurface:YES];
  176.     [status setHiddenThreeD:NO];
  177.     break;
  178.     case SURF_OPAQUE:
  179.     [status setSurface:YES];
  180.     [status setHiddenThreeD:YES];
  181.     break;
  182.     case SURF_INVISIBLE:
  183.     [status setSurface:NO];
  184.     [status setHiddenThreeD:NO];
  185.     break;
  186.     }
  187.  
  188.     [status setReport:oldReport];
  189.     [status reportSettingsChange:self];
  190.  
  191.     if ([self forceUpdateStatus:status doc:doc])
  192.     [view display];
  193.  
  194.     return self;
  195. }
  196.  
  197.  
  198. - doSetIsoSamples:sender
  199. {
  200.     int samples = [sender intValue];
  201.  
  202.     if (samples > 1)
  203.     [status setIsoSamplesCoord:[sender selectedTag] to:samples];
  204.     else
  205.     [sender setIntValue:[status isoSamples:[sender selectedTag]]];
  206.  
  207.     return self;
  208. }
  209.  
  210.  
  211. - doSetRotation:sender
  212. {
  213.     if (sender == rotMatrix)
  214.     [status setRotCoord:[sender selectedTag]
  215.              to:[[sender selectedCell] floatValue]];
  216.     else
  217.     if (sender == rotZSlider)
  218.         [status setRotCoord:Z_TAG to:359.0 - [sender floatValue]];
  219.     else
  220.         [status setRotCoord:[sender tag] to:[sender floatValue]];
  221.  
  222.     [self _updateRotationIsThreeD:[status isThreeD]];
  223.     return self;
  224. }
  225.  
  226.  
  227. - doResetRotation:sender
  228. {
  229.     [status resetRotation];
  230.     [self _updateRotationIsThreeD:[status isThreeD]];
  231.     return self;
  232. }
  233.  
  234.  
  235. - doSetContourBase:sender
  236. {
  237.     [status setContourBase:[sender state]];
  238.     if ([self forceUpdateStatus:status doc:doc])
  239.     [view display];
  240.     return self;
  241. }
  242.  
  243.  
  244. - doSetContourSurface:sender
  245. {
  246.     [status setContourSurface:[sender state]];
  247.     if ([self forceUpdateStatus:status doc:doc])
  248.     [view display];
  249.     return self;
  250. }
  251.  
  252.  
  253. - showContourOptionsPanel:sender
  254. {
  255.     if (!contourOptionsPanel)
  256.     contourOptionsPanel = [[ContourOptionsPanel allocFromZone:[self zone]]
  257.                    init];
  258.     [contourOptionsPanel showPanel:self];
  259.     return self;
  260. }
  261.  
  262.  
  263.  
  264. // Shuts up the compiler about unused RCSId
  265. - (const char *) rcsid
  266. {
  267.     return RCSId;
  268. }
  269.  
  270.  
  271. @end
  272.  
  273.  
  274.  
  275. @implementation ThreeDPane (Private)
  276.  
  277. - _updateRotationIsThreeD:(BOOL)isThreeD
  278. {
  279.     float aFloat;
  280.     Box *aBox;
  281.     Cell *aCell;
  282.     BOOL wasEnabled;
  283.  
  284.     [rotXSlider setFloatValue:aFloat = [status rotCoord:X_TAG]];
  285.     [rotXSlider setEnabled: isThreeD];
  286.     [aCell = [rotMatrix findCellWithTag:X_TAG] setFloatValue:aFloat];
  287.     [aCell setEnabled: isThreeD];
  288.  
  289.     [rotZSlider setFloatValue:359.0 - (aFloat = [status rotCoord:Z_TAG])];
  290.     [rotZSlider setEnabled: isThreeD];
  291.     [aCell = [rotMatrix findCellWithTag:Z_TAG] setFloatValue:aFloat];
  292.     [aCell setEnabled: isThreeD];
  293.  
  294.     [rotationResetButton setEnabled:isThreeD];
  295.  
  296.     /* 
  297.      *  If the plot is not threeD, we'll make the text title of the 
  298.      *  box dark gray to indicate that all 3d rotation is disabled.  
  299.      *  We only redisplay if the enabledment changes.
  300.      */
  301.     wasEnabled = [[aBox = [[rotXSlider superview] superview] cell] isEnabled];
  302.     if (wasEnabled != isThreeD)
  303.         [[aBox cell] setEnabled: isThreeD];
  304.  
  305.     return self;
  306. }
  307.  
  308.  
  309. - _updateContourIsThreeD:(BOOL)isThreeD
  310. {
  311.     BOOL isOpaque = [status hiddenThreeD];
  312.     BOOL contourBase = [status contourBase];
  313.     BOOL contourSurface = [status contourSurface];
  314.  
  315.     [[[[contourBaseButton superview] superview] cell] setEnabled:isThreeD];
  316.  
  317.     [contourBaseButton setState:contourBase];
  318.     [contourBaseButton setEnabled:isThreeD];
  319.  
  320.     /* 
  321.      * Contours on surfaces don't seem to show up when hidden
  322.      * line removal is turned on (in 3.3 beta).
  323.      */
  324.     //
  325.     [contourSurfaceButton setState:contourSurface && !isOpaque];
  326.     [contourSurfaceButton setEnabled:isThreeD && !isOpaque];
  327.  
  328.     [contourOptionsButton setEnabled:isThreeD && (contourBase ||
  329.                     (contourSurface && !isOpaque))];
  330.  
  331.     return self;
  332. }
  333.  
  334.  
  335.  
  336. - _updateSurfaceTypeIsThreeD:(BOOL)isThreeD
  337. {
  338.     Box *aBox;
  339.     BOOL wasEnabled;
  340.  
  341.     wasEnabled = [[aBox = [[surfaceTypeMatrix superview] superview]
  342.            cell] isEnabled];
  343.     if (wasEnabled != isThreeD)
  344.         [[aBox cell] setEnabled: isThreeD];
  345.  
  346.     if ([status surface]) {
  347.     if ([status hiddenThreeD])
  348.         [surfaceTypeMatrix selectCellWithTag:SURF_OPAQUE];
  349.     else
  350.         [surfaceTypeMatrix selectCellWithTag:SURF_WIREFRAME];
  351.     } else
  352.     [surfaceTypeMatrix selectCellWithTag:SURF_INVISIBLE];
  353.  
  354.     [surfaceTypeMatrix setEnabled:isThreeD];
  355.  
  356.     return self;
  357. }
  358.  
  359.  
  360.  
  361. - _updateIsoSamplesIsThreeD:(BOOL)isThreeD
  362. {
  363.     BOOL wasEnabled;
  364.     Box *aBox;
  365.  
  366.     [[isoSamplesMatrix findCellWithTag:X_TAG] setIntValue:
  367.      [status isoSamples:X_TAG]];
  368.  
  369.     [[isoSamplesMatrix findCellWithTag:Y_TAG] setIntValue:
  370.      [status isoSamples:Y_TAG]];
  371.  
  372.     [isoSamplesMatrix setEnabled:isThreeD];
  373.     [isoSamplesLabel setTextGray: isThreeD? NX_BLACK: NX_DKGRAY];
  374.  
  375.     wasEnabled = [[aBox = [[isoSamplesMatrix superview]
  376.                          superview] cell] isEnabled];
  377.     if (wasEnabled != isThreeD)
  378.     [[aBox cell] setEnabled: isThreeD];
  379.  
  380.     return self;
  381. }
  382.  
  383.  
  384.  
  385. @end
  386.